﻿namespace TestByWire.Tutorial.Domain
{
	public delegate void CalculationEvent(object sender);

	public class LegacyCode
	{
		private ICalculationEngine _summaryCalculator;
		private ICalculationEngine _anotherCalculator;

		public LegacyCode()
		{
			_summaryCalculator = new CalculationEngine();
			_anotherCalculator = new CalculationEngine();
		}

		public int FirstCalculationResult { get; set; }

		public int SecondCalculationResult { get; set; }

		public void Intialize()
		{
			_summaryCalculator.CalculationComplete += SummaryCalculatorCalculationComplete;
			_anotherCalculator.CalculationComplete += AnotherCalculatorCalculationComplete;
		}

		private void SummaryCalculatorCalculationComplete(object sender)
		{
			FirstCalculationResult += 10;
		}

		private void AnotherCalculatorCalculationComplete(object sender)
		{
			SecondCalculationResult += 20;
		}
	}

	public interface ICalculationEngine
	{
		event CalculationEvent CalculationComplete;

		void Calculate();
	}

	public class CalculationEngine : ICalculationEngine
	{
		public event CalculationEvent CalculationComplete;

		public void Calculate()
		{
		}
	}
}
